package corp.edu.amadeus.web.action;

import corp.edu.amadeus.web.action.navigation.NavegableActionBase;
import corp.edu.amadeus.core.business.object.impl.ContentBO;
import corp.edu.amadeus.core.business.service.ifc.IContentService;
import corp.edu.amadeus.core.business.locator.ServiceLocator;
import java.util.Collection;

import org.apache.log4j.Logger;

public class ContentAction extends NavegableActionBase {

	private static Logger log = Logger.getLogger(ContentAction.class);
	private Collection<ContentBO> contentsList;
	private IContentService contentService;
	private String description;
	private String lang;
	private String type;
	private Integer id;


	public ContentAction() {
		super();
		this.contentService = ServiceLocator.getContentService();
		this.contentsList = this.contentService.getAllContents();
	}

	public String execute() throws Exception {
		this.contentsList = this.contentService.getAllContents();
    	return SUCCESS;
    }

	public Collection<ContentBO> getContentsList() {
		return this.contentsList;
	}

	public void setContentsList(Collection<ContentBO> cL) {
		this.contentsList = cL;
	}

	public String create() throws Exception {
		if(this.id!=null) {
			this.contentService.updateContent(this.id, this.description, this.type, this.lang);
		} else {
			this.contentService.addContent(this.description, this.type, this.lang);
		}
		return this.execute();
	}

	public String list() throws Exception {
		return this.execute();
	}

	@Override
	public void loadMenu() {
		this.menu.put("Crear contenido: ", "createContent");
		this.menu.put("Componer contenido", "compositeContent");
	}

	public String getDescription() { return this.description; }
	public void setDescription(String d) { this.description = d; }

	public String getLang() { return this.lang; }
	public void setLang(String l) { this.lang = l; }

	public String getType() { return this.type; }
	public void setType(String t) { this.type = t; }

	public Integer getId() { return this.id; }
	public void setId(Integer i) { this.id = i; }

}